#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int arr[1000005];

// 最长上升子序列

void solve()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }

    reverse(arr + 1, arr + 1 + n);

    vector<int> vec;

    vec.push_back(arr[1]);

    for (int i = 2; i <= n; i++)
    {
        if (arr[i] > vec.back())
            vec.push_back(arr[i]);
        else
            *lower_bound(vec.begin(), vec.end(), arr[i]) = arr[i];
    }

    cout << vec.size() << endl;
}

// 最长不下降子序列

void solve2()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }

    reverse(arr + 1, arr + 1 + n);

    vector<int> vec;

    vec.push_back(arr[1]);

    for (int i = 2; i <= n; i++)
    {
        if (arr[i] >= vec.back())
            vec.push_back(arr[i]);
        else
            *upper_bound(vec.begin(), vec.end(), arr[i]) = arr[i];
    }

    cout << vec.size() << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}